export default function findTargetFromTree (tree, targetKey, keyName, childrenKeyName = 'children') {
  let target = tree.find(item => targetKey === item[keyName])
  if (target) {
    return target
  }

  tree.some(item => {
    if (item[childrenKeyName] && item[childrenKeyName].length > 0) {
      target = findTargetFromTree(item[childrenKeyName], targetKey, keyName, childrenKeyName)
      return !!target
    }
    return false
  })

  return target
}